package com.shop.mms_client.ui;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.recyclerview.widget.DiffUtil;
import androidx.recyclerview.widget.ListAdapter;
import androidx.recyclerview.widget.RecyclerView;
import com.shop.mms_client.R;
import com.shop.mms_client.model.BlacklistItem;

public class BlacklistAdapter extends ListAdapter<BlacklistItem, BlacklistAdapter.ViewHolder> {
    
    protected BlacklistAdapter() {
        super(new DiffUtil.ItemCallback<BlacklistItem>() {
            @Override
            public boolean areItemsTheSame(BlacklistItem oldItem, BlacklistItem newItem) {
                return oldItem.getId() == newItem.getId();
            }

            @Override
            public boolean areContentsTheSame(BlacklistItem oldItem, BlacklistItem newItem) {
                return oldItem.getValue().equals(newItem.getValue()) && 
                       oldItem.getType().equals(newItem.getType());
            }
        });
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext())
            .inflate(R.layout.item_blacklist, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        BlacklistItem item = getItem(position);
        holder.bind(item);
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        private final TextView valueText;
        private final TextView typeText;

        ViewHolder(View view) {
            super(view);
            valueText = view.findViewById(R.id.valueText);
            typeText = view.findViewById(R.id.typeText);
        }

        void bind(BlacklistItem item) {
            valueText.setText(item.getValue());
            typeText.setText(item.getType());
        }
    }
} 